/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package type;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author sunwei
 */
public enum SalesForecastPeriodType {
    
    FirstHalf(1),
    SecondHalf(2);
    
    private static final Map<Integer, SalesForecastPeriodType> numberToPeriodTypeMap;
    private final int periodNum;

    static {
        numberToPeriodTypeMap = new HashMap<Integer,SalesForecastPeriodType>();
        for (SalesForecastPeriodType periodType : EnumSet.allOf(SalesForecastPeriodType.class)) {
            numberToPeriodTypeMap.put(periodType.getPeriodNum(), periodType );
        }
    }

    private SalesForecastPeriodType(int periodNum) {
        this.periodNum = periodNum;
    }

    public int getPeriodNum() {
        return periodNum;
    }

    public static SalesForecastPeriodType  fromPeriodNum(int value) {
        SalesForecastPeriodType ret = numberToPeriodTypeMap.get(value);
        if (ret == null) {
            throw new IllegalArgumentException(); // Or just return null
        }
        return ret;
    }
}
